import React, { Component } from 'react';
import { Table } from 'antd'
import PropTypes from 'prop-types'
class TableLay extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    //table选择事件
    rowSelection = {
        onChange: (selectedRowKeys, selectedRows) => {
            this.props.onCheckRow(selectedRows, selectedRowKeys);
        },
        getCheckboxProps: (record) => ({
            disabled: record.name === 'Disabled User',
            name: record.name,
        }),
    };
    render() {
        let { dataSource, columns, selectionType, rowKey, pagination } = this.props;
        //检测selectionType 是否存在值
        let tabProp = {}
        if (selectionType) {
            tabProp['rowSelection'] = {
                type: selectionType,
                ...this.rowSelection
            }
        }
        return (
            <>
                <Table pagination={pagination} rowKey={rowKey} {...tabProp} dataSource={dataSource} columns={columns} />;
            </>
        );
    }
}
TableLay.propTypes = {
    dataSource: PropTypes.array,
    columns: PropTypes.array,
    selectionType: PropTypes.oneOf(['checkbox', 'radio']),
    rowKey: PropTypes.string,
    onCheckRow: PropTypes.func,
    pagination: PropTypes.oneOfType([PropTypes.object, PropTypes.bool])
}
TableLay.defaultProps = {
    dataSource: [],
    columns: [],
    pagination: false
}

export default TableLay;